package com.hyg.lib_music.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.utils.TextUtils;
import com.hyg.lib_music.R;
import com.hyg.lib_music.modle.knowledgeCategoryData;

import java.util.List;

/**
 * @author: Administrator
 * @date: 2021/4/12
 */
public class knowlegeCategotyAdapter extends RecyclerView.Adapter<knowlegeCategotyAdapter.ViewHolder> {

    Context context;
    List<knowledgeCategoryData.DataDTO> list;

    public knowlegeCategotyAdapter(Context context, List<knowledgeCategoryData.DataDTO> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_knowledge_category, parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        if(TextUtils.isEmpty(list.get(position).getCategoryName())){
            holder.nameTv.setVisibility(View.GONE);
        }else{
            holder.nameTv.setText(list.get(position).getCategoryName());
        }

        LinearLayoutManager layoutManager = new LinearLayoutManager(context);
        holder.recyclerView.setLayoutManager(layoutManager);
        holder.recyclerView.setAdapter(new KnowLedgeCategorySecondAdapter(context, list.get(position).getDocList()));
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        TextView nameTv;
        RecyclerView recyclerView;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            nameTv = itemView.findViewById(R.id.tv_category_name);
            recyclerView = itemView.findViewById(R.id.rcv_categoty);
        }
    }
}
